package xipujewel.xipujewel.utils;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class jxlUtil {

	/**
	 *
	 * @param file
	 * @return
	 */
	public static List<Map<Integer, String>> loadCXL(InputStream inputStream) {
		List<Map<Integer, String>> table = new ArrayList<Map<Integer, String>>();
		try {
			Workbook book = Workbook.getWorkbook(inputStream);
			Sheet sheet = book.getSheet(0);
			int rows = sheet.getRows();
			int cols = sheet.getColumns();
			for (int i = 1; i <= rows; i++) {
				Map<Integer, String> row = new HashMap<Integer, String>();
				for (int j = 1; j <= cols; j++) {
					row.put(j, sheet.getCell(j - 1, i - 1).getContents());
				}
				table.add(row);
			}
		} catch (BiffException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return table;
	}
}
